/**
 * Copyright &copy; 2012-2014 <a href="https://github.cn.apestar">JeeSite</a> All rights reserved.
 */
package cn.apestar.modules.common.feedback.service;

import java.util.List;

import cn.apestar.common.utils.CommonUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.apestar.common.persistence.Page;
import cn.apestar.common.service.CrudService;
import cn.apestar.modules.common.feedback.dao.SysImageDao;
import cn.apestar.modules.common.feedback.entity.SysImage;
import cn.apestar.modules.sys.entity.Institution;
/**
 * 任务图片Service
 * @author lvh
 * @version 2016-07-10
 */
@Service
@Transactional(readOnly = true)
public class SysImageService extends CrudService<SysImageDao, SysImage> {

    public SysImage get(String id) {
        return super.get(id);
    }

    public List<SysImage> findList(SysImage sysImage) {
        return super.findList(sysImage);
    }

    public Page<SysImage> findPage(Page<SysImage> page, SysImage sysImage) {
        return super.findPage(page, sysImage);
    }

    @Transactional(readOnly = false)
    public void save(SysImage sysImage) {
        super.save(sysImage);
    }

    @Transactional(readOnly = false)
    public void delete(SysImage sysImage) {
        super.delete(sysImage);
    }

    @Transactional(readOnly = false)
    public void setImage(Institution institution, String key, String imageType) {
        List<SysImage> imageList = getImageListByImageType(institution.getId(), imageType);
        for (int i = 0; i < imageList.size(); i++) {
            int j = i + 1;
            String keys = key + j;
            SysImage w = imageList.get(i);
            CommonUtil.setProperty(institution, keys, w.getUrl());
            if (i == 5)
                break;
        }
    }

    public List<SysImage> getImageListByImageType(String dataId, String type) {
        SysImage w = new SysImage();
        w.setDataId(dataId);
        w.setImageType(type);
        return findList(w);
    }
}